var URL = "http://192.168.0.116:8080/Jsonp/Jsonp";
function getSerial(){
	var today = new Date();
	var year = today.getFullYear();
	var month = today.getMonth() < 9 ? "0" + (today.getMonth() + 1) : (today.getMonth() + 1);
	var date = today.getDate() < 10 ? "0" + today.getDate() : today.getDate();
	var hour = today.getHours();
	var min = today.getMinutes();
	var sec = today.getSeconds();
	var msec = today.getMilliseconds();

	return year + month + date + hour + min + sec + msec + Math.floor(Math.random()*1000000)
}
		
function Driver() {
	$.jsonp.setup({
		url: URL,
		callbackParameter:"jsonpcallback",
	});
}

// 获得插件版本
Driver.prototype.getPluginVer = function(callback) {
	$.jsonp( {
		data : 'action=getPluginVer',
		success : function(data) {
			callback(data);
		},
		error : function(xOptions, textStatus) {
			var str = '';
			if (textStatus == "error") {
				str += '{"ret_code":"2", "ret_msg":"请求失败[不可达]"}';
			} else if (textStatus == "timeout") {
				str += '{"ret_code":"3", "ret_msg":"请求失败[超时]"}';
			}
			var obj;
			eval("obj=" + str);

			callback(obj);
		}
	});
}

// 查询拍照设备信息
Driver.prototype.getCameraInfo = function(callback) {
	$.jsonp( {
		data : 'action=getCameraInfo',

		success : function(data) {
			callback(data);
		},
		error : function(xOptions, textStatus) {
			var str = '';
			if (textStatus == "error") {
				str += '{"ret_code":"2", "ret_msg":"请求失败[不可达]"}';
			} else if (textStatus == "timeout") {
				str += '{"ret_code":"3", "ret_msg":"请求失败[超时]"}';
			}
			var obj;
			eval("obj=" + str);

			callback(obj);
		}
	});
}

// 查询副屏信息
Driver.prototype.getSubScreenInfo = function(callback) {
	$.jsonp( {
		data : 'action=getSubScreenInfo',

		success : function(data) {
			callback(data);
		},
		error : function(xOptions, textStatus) {
			var str = '';
			if (textStatus == "error") {
				str += '{"ret_code":"2", "ret_msg":"请求失败[不可达]"}';
			} else if (textStatus == "timeout") {
				str += '{"ret_code":"3", "ret_msg":"请求失败[超时]"}';
			}
			var obj;
			eval("obj=" + str);

			callback(obj);
		}
	});
}

// 查询二代证设备信息
Driver.prototype.getIDCardEquipInfo = function(callback) {
	$.jsonp( {
		data : 'action=getIDCardEquipInfo',

		success : function(data) {
			callback(data);
		},
		error : function(xOptions, textStatus) {
			var str = '';
			if (textStatus == "error") {
				str += '{"ret_code":"2", "ret_msg":"请求失败[不可达]"}';
			} else if (textStatus == "timeout") {
				str += '{"ret_code":"3", "ret_msg":"请求失败[超时]"}';
			}
			var obj;
			eval("obj=" + str);

			callback(obj);
		}
	});
}

// 拍照设置
Driver.prototype.setCamera = function(resolution_x, resolution_y, size,
		quliaty, format,callback) {
	$.jsonp( {
		data : 'action=setCamera&resolution_x=' + resolution_x
				+ '&resolution_y=' + resolution_y + '&size=' + size
				+ '&quliaty=' + quliaty + '&format=' + format,

		success : function(data) {
			callback(data);
		},
		error : function(xOptions, textStatus) {
			var str = '';
			if (textStatus == "error") {
				str += '{"ret_code":"2", "ret_msg":"请求失败[不可达]"}';
			} else if (textStatus == "timeout") {
				str += '{"ret_code":"3", "ret_msg":"请求失败[超时]"}';
			}
			var obj;
			eval("obj=" + str);

			callback(obj);
		}
	});
}

// 手写签名设置
Driver.prototype.setHandSign = function(size, format, position,callback) {
	$.jsonp( {
		data : 'action=setHandSign&size=' + size + '&format=' + format
				+ '&position' + position,

		success : function(data) {
			callback(data);
		},
		error : function(xOptions, textStatus) {
			var str = '';
			if (textStatus == "error") {
				str += '{"ret_code":"2", "ret_msg":"请求失败[不可达]"}';
			} else if (textStatus == "timeout") {
				str += '{"ret_code":"3", "ret_msg":"请求失败[超时]"}';
			}
			var obj;
			eval("obj=" + str);

			callback(obj);
		}
	});
}

	// 获得插件版本
	function callGetPluginVer(callback) {
		var driver = new Driver();
		driver.getPluginVer(callback);
	}
	// 查询拍照设备信息
	function callGetCameraInfo(callback) {
		var driver = new Driver();
		driver.getCameraInfo(callback);
	}
	// 查询副屏信息
	function callGetSubScreenInfo(callback) {
		var driver = new Driver();
		driver.getSubScreenInfo(callback);
	}
	// 查询二代证设备信息
	function callGetIDCardEquipInfo(callback) {
		var driver = new Driver();
		driver.getIDCardEquipInfo(callback);
	}
	// 拍照设置
	function callSetCamera(resolution_x,resolution_y,size,quliaty, format,callback) {
		var driver = new Driver();
		driver.setCamera(resolution_x,resolution_y,size,quliaty, format,callback);
	}
	// 手写签名设置
	function callSetHandSign(size, format, position, callback) {
		var driver = new Driver();
		driver.setHandSign(size, format, position, callback);
	}